package org.shock.ss.sms.service.app.impl;

import org.shock.ss.sms.bean.app.InRecords;
import org.shock.ss.sms.commons.dao.BaseDao;
import org.shock.ss.sms.commons.db.ProxoolDbPool;
import org.shock.ss.sms.commons.db.TsDbTools;
import org.shock.ss.sms.commons.service.impl.BaseServiceImpl;
import org.shock.ss.sms.service.app.InRecordsService;

public class InRecordsServiceImpl extends BaseServiceImpl implements InRecordsService {
	public InRecordsServiceImpl(BaseDao dao) {
		super(dao);
	}

	@Override
	public void add(Object bean) throws Exception {
		InRecords in = (InRecords) bean;
		try {
			tx = ProxoolDbPool.getTranManager();
			tx.beginTransaction();
			// TODO Auto-generated method stub
			dao.add(in);
			for (int i = 0; i < in.getCargonum(); i++) {
				TsDbTools.doSql("insert into ckgl_cargoplu (cargoid,plu)values(" + in.getCargoid() + "," + (i+1) + ")");
			}
			tx.commitAndClose();
		} catch (Exception e) {
			if (tx != null) {
				tx.rollbackAndClose();
			}
			throw e;
		}
	}

	@Override
	public void update(Object bean) throws Exception {
		InRecords in = (InRecords) bean;
		try {
			tx = ProxoolDbPool.getTranManager();
			tx.beginTransaction();
			// TODO Auto-generated method stub
			dao.update(in);
			TsDbTools.doSql("delete from ckgl_cargoplu where cargoid=" + in.getCargoid());
			for (int i = 0; i < in.getCargonum(); i++) {
				TsDbTools.doSql("insert into ckgl_cargoplu (cargoid,plu)values(" + in.getCargoid() + "," + (i+1) + ")");
			}
			tx.commitAndClose();
		} catch (Exception e) {
			if (tx != null) {
				tx.rollbackAndClose();
			}
			throw e;
		}
	}
}